﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using JXT.PrimaryKey.Batman.Language;
using JXT.PrimaryKey.Batman.Container;
using JXT.PrimaryKey.Batman.Core.Infrastructure;

namespace JXT.PrimaryKey.Batman.Core.Language
{
    /// <summary>
    /// 多语言扩展类
    /// </summary>
    public static class LanguageExtensions
    {
        //private static ILanguage _languageService;

        //private static ILanguage Language
        //{
        //    get
        //    {
        //        if (_languageService == null)
        //        {
        //            _languageService = ContainerManager.Default.Resolve<ILanguage>();
        //        }
        //        return _languageService;
        //    }
        //}

        /// <summary>
        /// 转换语言
        /// </summary>
        /// <param name="context">系统上下文对象</param>
        /// <param name="key">语言Key</param>
        /// <returns>转换结果</returns>
        public static string String(this SupernovaContext context, string key)
        {
            return context.Language.Localize(key, context.CultureInfo);
        }

        /// <summary>
        /// 转换语言
        /// </summary>
        /// <param name="context">系统上下文对象</param>
        /// <param name="key">语言Key</param>
        /// <param name="defaultValue">默认值</param>
        /// <returns>转换结果</returns>
        public static string String(this SupernovaContext context, string key, string defaultValue)
        {
            return context.Language.Localize(key, defaultValue, context.CultureInfo);
        }
    }
}
